// to do

#include<iostream>
#include<string>
#include<stack>
using namespace std;

string decodeString(string str) {
    stack<char> stk;
    int idx = 0;
    string ch, tmp, kStr, encodeStr;
    int cnt(1);
    while (idx < str.size()) {
        tmp.clear();
        encodeStr.clear();
        if (str[idx] == ']') {
            while(!stk.empty() && stk.top() != '[') {
                ch = stk.top();
                tmp = ch + tmp;
                stk.pop();
            }
            // skip [
            if (!stk.empty() && stk.top() == '[') {
                stk.pop();
            }
            kStr.clear();
            // get k value
            while(!stk.empty() && isdigit(stk.top())) {
                ch = stk.top();
                stk.pop();
                kStr = ch + kStr;
            }
            if (kStr.size() > 0) {
                cnt = stoi(kStr);
                while(cnt > 0) {
                    encodeStr += tmp;
                    cnt--;
                }
            } else {
                encodeStr = tmp;
            }
            for (char c : encodeStr) {
                stk.push(c);
            }
        } else {
            stk.push(str[idx]);
        }
        idx++;
    }
    string res;
    while(!stk.empty()) {
        res = stk.top() + res;
        stk.pop();
    }
    return res;
}

int main() {
    // string str = "3[a]2[bc]";
    string str = "3[a2[c]]";
    stack<char> stk;
    int idx = 0;
    string ch, tmp, kStr, encodeStr;
    int cnt(1);
    while (idx < str.size()) {
        // cout << "idx: " << idx << endl;
        tmp.clear();
        encodeStr.clear();
        if (str[idx] == ']') {
            while(!stk.empty() && stk.top() != '[') {
                ch = stk.top();
                tmp = ch + tmp;
                stk.pop();
            }
            // cout << tmp << endl;
            // skip [
            if (!stk.empty() && stk.top() == '[') {
                stk.pop();
            }
            kStr.clear();
            // get k value
            while(!stk.empty() && isdigit(stk.top())) {
                ch = stk.top();
                stk.pop();
                kStr = ch + kStr;
            }
            if (kStr.size() > 0) {
                cnt = stoi(kStr);
                while(cnt > 0) {
                    // cout << cnt << endl;
                    encodeStr += tmp;
                    // cout << "encodeStr: " << encodeStr << endl;
                    cnt--;
                }
            } else {
                encodeStr = tmp;
            }
            for (char c : encodeStr) {
                stk.push(c);
            }
        } else {
            stk.push(str[idx]);
        }
        idx++;
    }
    string res;
    while(!stk.empty()) {
        res = stk.top() + res;
        stk.pop();
    }
    cout << res << endl;
}